package b.i.i;

import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import b.i.i.d.c;
import java.util.Locale;

/* compiled from: BidiFormatter */
public final class a {
    public static final c d;
    public static final String e = Character.toString(8206);
    public static final String f = Character.toString(8207);
    public static final a g;
    public static final a h;
    public final boolean a;
    public final int b;
    public final c c;

    /* compiled from: BidiFormatter */
    public static class a {
        public static final byte[] e = new byte[1792];
        public final CharSequence a;
        public final int b;
        public int c;
        public char d;

        static {
            for (int i = 0; i < 1792; i++) {
                e[i] = Character.getDirectionality(i);
            }
        }

        public a(CharSequence charSequence, boolean z) {
            this.a = charSequence;
            this.b = charSequence.length();
        }

        public byte a() {
            char charAt = this.a.charAt(this.c - 1);
            this.d = charAt;
            if (Character.isLowSurrogate(charAt)) {
                int codePointBefore = Character.codePointBefore(this.a, this.c);
                this.c -= Character.charCount(codePointBefore);
                return Character.getDirectionality(codePointBefore);
            }
            this.c--;
            charAt = this.d;
            return charAt < 1792 ? e[charAt] : Character.getDirectionality(charAt);
        }
    }

    static {
        c cVar = d.c;
        d = cVar;
        g = new a(false, 2, cVar);
        h = new a(true, 2, cVar);
    }

    public a(boolean z, int i, c cVar) {
        this.a = z;
        this.b = i;
        this.c = cVar;
    }

    /* JADX WARNING: Missing block: B:37:0x008e, code skipped:
            r5 = r5 - 1;
     */
    /* JADX WARNING: Missing block: B:56:?, code skipped:
            return 1;
     */
    public static int a(java.lang.CharSequence r9) {
        /*
        r0 = new b.i.i.a$a;
        r1 = 0;
        r0.m501init(r9, r1);
        r0.c = r1;
        r9 = -1;
        r2 = 1;
        r3 = 0;
        r4 = 0;
        r5 = 0;
    L_0x000d:
        r6 = r0.c;
        r7 = r0.b;
        if (r6 >= r7) goto L_0x0070;
    L_0x0013:
        if (r3 != 0) goto L_0x0070;
    L_0x0015:
        r7 = r0.a;
        r6 = r7.charAt(r6);
        r0.d = r6;
        r6 = java.lang.Character.isHighSurrogate(r6);
        if (r6 == 0) goto L_0x0039;
    L_0x0023:
        r6 = r0.a;
        r7 = r0.c;
        r6 = java.lang.Character.codePointAt(r6, r7);
        r7 = r0.c;
        r8 = java.lang.Character.charCount(r6);
        r8 = r8 + r7;
        r0.c = r8;
        r6 = java.lang.Character.getDirectionality(r6);
        goto L_0x004d;
    L_0x0039:
        r6 = r0.c;
        r6 = r6 + r2;
        r0.c = r6;
        r6 = r0.d;
        r7 = 1792; // 0x700 float:2.511E-42 double:8.854E-321;
        if (r6 >= r7) goto L_0x0049;
    L_0x0044:
        r7 = b.i.i.a.a.e;
        r6 = r7[r6];
        goto L_0x004d;
    L_0x0049:
        r6 = java.lang.Character.getDirectionality(r6);
    L_0x004d:
        if (r6 == 0) goto L_0x006b;
    L_0x004f:
        if (r6 == r2) goto L_0x0068;
    L_0x0051:
        r7 = 2;
        if (r6 == r7) goto L_0x0068;
    L_0x0054:
        r7 = 9;
        if (r6 == r7) goto L_0x000d;
    L_0x0058:
        switch(r6) {
            case 14: goto L_0x0064;
            case 15: goto L_0x0064;
            case 16: goto L_0x0060;
            case 17: goto L_0x0060;
            case 18: goto L_0x005c;
            default: goto L_0x005b;
        };
    L_0x005b:
        goto L_0x006e;
    L_0x005c:
        r5 = r5 + -1;
        r4 = 0;
        goto L_0x000d;
    L_0x0060:
        r5 = r5 + 1;
        r4 = 1;
        goto L_0x000d;
    L_0x0064:
        r5 = r5 + 1;
        r4 = -1;
        goto L_0x000d;
    L_0x0068:
        if (r5 != 0) goto L_0x006e;
    L_0x006a:
        goto L_0x0088;
    L_0x006b:
        if (r5 != 0) goto L_0x006e;
    L_0x006d:
        goto L_0x008c;
    L_0x006e:
        r3 = r5;
        goto L_0x000d;
    L_0x0070:
        if (r3 != 0) goto L_0x0073;
    L_0x0072:
        goto L_0x0091;
    L_0x0073:
        if (r4 == 0) goto L_0x0077;
    L_0x0075:
        r1 = r4;
        goto L_0x0091;
    L_0x0077:
        r4 = r0.c;
        if (r4 <= 0) goto L_0x0091;
    L_0x007b:
        r4 = r0.a();
        switch(r4) {
            case 14: goto L_0x008a;
            case 15: goto L_0x008a;
            case 16: goto L_0x0086;
            case 17: goto L_0x0086;
            case 18: goto L_0x0083;
            default: goto L_0x0082;
        };
    L_0x0082:
        goto L_0x0077;
    L_0x0083:
        r5 = r5 + 1;
        goto L_0x0077;
    L_0x0086:
        if (r3 != r5) goto L_0x008e;
    L_0x0088:
        r1 = 1;
        goto L_0x0091;
    L_0x008a:
        if (r3 != r5) goto L_0x008e;
    L_0x008c:
        r1 = -1;
        goto L_0x0091;
    L_0x008e:
        r5 = r5 + -1;
        goto L_0x0077;
    L_0x0091:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.i.a.a(java.lang.CharSequence):int");
    }

    /* JADX WARNING: Missing block: B:15:0x002f, code skipped:
            r6 = r6 - 1;
     */
    public static int b(java.lang.CharSequence r6) {
        /*
        r0 = new b.i.i.a$a;
        r1 = 0;
        r0.m501init(r6, r1);
        r6 = r0.b;
        r0.c = r6;
        r6 = 0;
        r2 = 0;
    L_0x000c:
        r3 = r0.c;
        r4 = 1;
        if (r3 <= 0) goto L_0x0041;
    L_0x0011:
        r3 = r0.a();
        if (r3 == 0) goto L_0x0039;
    L_0x0017:
        if (r3 == r4) goto L_0x0032;
    L_0x0019:
        r5 = 2;
        if (r3 == r5) goto L_0x0032;
    L_0x001c:
        r5 = 9;
        if (r3 == r5) goto L_0x000c;
    L_0x0020:
        switch(r3) {
            case 14: goto L_0x002c;
            case 15: goto L_0x002c;
            case 16: goto L_0x0029;
            case 17: goto L_0x0029;
            case 18: goto L_0x0026;
            default: goto L_0x0023;
        };
    L_0x0023:
        if (r2 != 0) goto L_0x000c;
    L_0x0025:
        goto L_0x003f;
    L_0x0026:
        r6 = r6 + 1;
        goto L_0x000c;
    L_0x0029:
        if (r2 != r6) goto L_0x002f;
    L_0x002b:
        goto L_0x0034;
    L_0x002c:
        if (r2 != r6) goto L_0x002f;
    L_0x002e:
        goto L_0x003b;
    L_0x002f:
        r6 = r6 + -1;
        goto L_0x000c;
    L_0x0032:
        if (r6 != 0) goto L_0x0036;
    L_0x0034:
        r1 = 1;
        goto L_0x0041;
    L_0x0036:
        if (r2 != 0) goto L_0x000c;
    L_0x0038:
        goto L_0x003f;
    L_0x0039:
        if (r6 != 0) goto L_0x003d;
    L_0x003b:
        r1 = -1;
        goto L_0x0041;
    L_0x003d:
        if (r2 != 0) goto L_0x000c;
    L_0x003f:
        r2 = r6;
        goto L_0x000c;
    L_0x0041:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.i.a.b(java.lang.CharSequence):int");
    }

    public static a c() {
        Locale locale = Locale.getDefault();
        Locale locale2 = e.a;
        boolean z = true;
        if (TextUtils.getLayoutDirectionFromLocale(locale) != 1) {
            z = false;
        }
        c cVar = d;
        if (cVar == d) {
            return z ? h : g;
        } else {
            return new a(z, 2, cVar);
        }
    }

    public CharSequence d(CharSequence charSequence, c cVar, boolean z) {
        if (charSequence == null) {
            return null;
        }
        boolean b = ((c) cVar).b(charSequence, 0, charSequence.length());
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        CharSequence charSequence2 = "";
        if (((this.b & 2) != 0 ? 1 : null) != null && z) {
            boolean b2 = ((c) (b ? d.b : d.a)).b(charSequence, 0, charSequence.length());
            CharSequence charSequence3 = (this.a || !(b2 || a(charSequence) == 1)) ? (!this.a || (b2 && a(charSequence) != -1)) ? charSequence2 : f : e;
            spannableStringBuilder.append(charSequence3);
        }
        if (b != this.a) {
            spannableStringBuilder.append(b ? 8235 : 8234);
            spannableStringBuilder.append(charSequence);
            spannableStringBuilder.append(8236);
        } else {
            spannableStringBuilder.append(charSequence);
        }
        if (z) {
            b = ((c) (b ? d.b : d.a)).b(charSequence, 0, charSequence.length());
            if (!this.a && (b || b(charSequence) == 1)) {
                charSequence2 = e;
            } else if (this.a && (!b || b(charSequence) == -1)) {
                charSequence2 = f;
            }
            spannableStringBuilder.append(charSequence2);
        }
        return spannableStringBuilder;
    }
}
